<?php

/**
 * SectionModel
 *
 * @author Nguyen Tuan Anh
 * @version
 */

require_once 'Zend/Db/Table/Abstract.php';

class SectionModel extends Zend_Db_Table_Abstract {
	/**
	 * The default table name
	 */
	protected $_name = 'eway_section';
	protected $_dbAdapter;

	public function getAll() {
		$this->_dbAdapter = Zend_Registry::get ( Constant::DB_ADAPTER );
		$sql = "SELECT * FROM ".$this->_name." ORDER BY sec_position ASC";
		$result = $this->_dbAdapter->fetchAll ( $sql );
		return $result;
	}

	/** Dung cho trang chu */
//	public function getAllSectionAndCategory() {
//		$this->_dbAdapter = Zend_Registry::get ( Constant::DB_ADAPTER );
//		$sql = "SELECT * FROM ".$this->_name ." s "
//		. "INNER JOIN eway_category c "
//		. "ON s.sec_id=c.sec_id "
//		. "ORDER BY s.sec_position ASC";
//		$result = $this->_dbAdapter->fetchAll ( $sql );
//		return $result;
//	}
	
	function getPriceBySectionId($section_id){
		$this->_dbAdapter = Zend_Registry::get ( Constant::DB_ADAPTER );
		$sql = "SELECT sec_price FROM ".$this->_name." WHERE sec_id=?";
		$result = $this->_dbAdapter->fetchCol($sql, $section_id);
		return $result[0];
	}

	function getMaxPrice(){
		$this->_dbAdapter = Zend_Registry::get ( Constant::DB_ADAPTER );
		$sql = "SELECT MAX(sec_price) FROM ".$this->_name;
		$result = $this->_dbAdapter->fetchCol($sql);
		return $result[0];
	}
}
